package com.llkj.qingnianguoxue.adapter;

import android.widget.FrameLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.llkj.qingnianguoxue.R;
import com.llkj.qingnianguoxue.bean.BookTabBean;
import com.llkj.qingnianguoxue.util.DisplayUtil;

import java.util.List;

/**
 * 精选图书Tab
 */
public class JingXuanBookTabAdapter extends BaseQuickAdapter<BookTabBean, BaseViewHolder> {

    private int mCurrentPosition;
    private int mType;
    public JingXuanBookTabAdapter(int layoutResId, List<BookTabBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, BookTabBean item) {
        baseViewHolder.setText(R.id.tvTab, item.getTilte());

        FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) baseViewHolder.getView(R.id.tvTab).getLayoutParams();
        if(mType==1){
            params.width = DisplayUtil.getDensityWdith(mContext) / mData.size();
            FrameLayout.LayoutParams paramsLine = (FrameLayout.LayoutParams) baseViewHolder.getView(R.id.lineBottom).getLayoutParams();
            paramsLine.width = DisplayUtil.dip2px(mContext,80);
        }else {
            params.width = DisplayUtil.getDensityWdith(mContext) / 2;
        }

        FrameLayout flItem = baseViewHolder.getView(R.id.fl_item);
        if(mCurrentPosition==baseViewHolder.getLayoutPosition()){
            flItem.setSelected(true);
        }else{
            flItem.setSelected(false);
        }
    }

    public void setSelectPosition(int position){
        mCurrentPosition = position;
        notifyDataSetChanged();
    }

    public void setType(int type){
        mType = type;
    }
}
